package com.gec.zhs.controller;

import com.gec.zhs.annotation.RecordUserMessage;
import com.gec.zhs.annotation.ZhsLogin;
import com.gec.zhs.entity.constants.Constants;
import com.gec.zhs.entity.enums.MessageTypeEnum;
import com.gec.zhs.entity.pojo.UserAction;
import com.gec.zhs.entity.vo.ResponseVO;
import com.gec.zhs.service.UserActionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Size;

/**
 * @author zhs
 * @version 1.0
 * @date 2025-02-15
 * @description 用户的行为，点赞，投币，收藏
 */
@RestController
@RequestMapping("/userAction")
public class UserActionController extends ABaseController {

    @Autowired
    private UserActionService userActionService;

    @ApiOperation("点赞投币收藏/一键三连")
    @RequestMapping("/doAction")
    @ZhsLogin(checkLogin = true)
    @RecordUserMessage(messageType = MessageTypeEnum.LIKE)
    public ResponseVO doAction(String videoId, Integer actionType,
                               @Max(2) @Min(1) Integer actionCount,
                               Integer commentId) {
        UserAction userAction = new UserAction();
        userAction.setUserId(getTokenUserInfoDto().getUserId());
        userAction.setVideoId(videoId);
        userAction.setActionType(actionType);
        userAction.setActionCount(actionCount == null ? Constants.ONE : actionCount);
        userAction.setCommentId(commentId == null ? Constants.ZERO : commentId);

        userActionService.saveAction(userAction);
        return getSuccessResponseVO(null);
    }


}
